package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.IssuePolicy;
import cn.wolfcode.crm.domain.Policy;
import cn.wolfcode.crm.domain.Product;
import cn.wolfcode.crm.mapper.IssuepolicyMapper;
import cn.wolfcode.crm.mapper.PolicyMapper;
import cn.wolfcode.crm.mapper.ProductMapper;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.IssuePolicyQueryObj;
import cn.wolfcode.crm.service.IIssuepolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
<<<<<<< HEAD
=======
import sun.security.x509.PolicyMappingsExtension;
>>>>>>> 524224bf820c6d6da01f752551ee21b728709493

import java.util.List;

@Service
public class IssuepolicyServiceImpl implements IIssuepolicyService {

    @Autowired
    private IssuepolicyMapper issuepolicyMapper;

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private PolicyMapper policyMapper;

    @Override
    public PageResult query(IssuePolicyQueryObj qo) {
        int total = issuepolicyMapper.queryForCount(qo);
        if (total == 0) {
            return new PageResult();
        }
        List list = issuepolicyMapper.queryForList(qo);
        return new PageResult(total, list);
    }

    @Override
    public void deleteByPrimaryKey(Long id) {
        issuepolicyMapper.deleteByPrimaryKey(id);
    }


    @Override
    public List<Product> selectProductBySn(String sn) {

        List<Product> list = productMapper.selectProductBySn(sn);
        return list;
    }

    @Override
    public void update(IssuePolicy issuePolicy) {
        issuepolicyMapper.updateByPrimaryKey(issuePolicy);
        Policy policy = issuePolicy.getPolicy();
        policy.setState(4);
        policyMapper.updateState(policy);

    }


}
